import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// import vueDevTools from 'vite-plugin-vue-devtools'
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";

export default defineConfig(({ mode }) => {
  // 通过 mode 参数判断环境
  //const isDev = mode === "development";

  return {
    // base: isDev ? './' : '/comfyui/',
    base: "./",
    plugins: [
      vue(),
      Components({
        resolvers: [VantResolver()],
      }),
    ],
    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    server: {
      host: "0.0.0.0", // 允许所有网络接口访问（关键配置）
      port: 5173, // 默认端口，可自定义（如3000）
      strictPort: false, // 端口冲突时自动尝试下一个端口
      proxy: {
        "/dev-api": {
          // target: "http://47.237.77.65:8080",
          target: "https://www.hubaicreating.com",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/dev-api/, ""),
        },
      },
    },
  };
});
